﻿using CefSharp;
using CefSharp.WinForms;
using CefSharp.WinForms.Example;
using MyCef.service;
using System;
using System.Windows.Forms;

namespace MyCef
{
    public partial class Form1 : Form
    {

        #region 初始化
        public Form1()
        {
            InitializeComponent();
            InitializeChromium();
        }

        /// <summary>
        ///  初始化浏览器并启动
        /// </summary>
        public void InitializeChromium()
        {
            this.AddPage("www.baidu.com");
        }


        private void AddPage(string url, int? insertIndex = null)
        {
            mainPanel.SuspendLayout();
            var browser = new FullScreenBrowser(AddPage, url, true)
            {
                Dock = DockStyle.Fill,
            };
            browser.CreateControl();
            mainPanel.Controls.Add(browser);
            mainPanel.ResumeLayout(true);
        }

        #endregion
        #region 页面事件
        /// <summary>
        /// 关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_FormClosing(object sender, EventArgs e)
        {
            Cef.Shutdown();
        }
        /// <summary>
        /// 按键抬起
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {

        }
        #endregion
    }
}
